import request from '@/utils/request'

export function listRole(params) {
  return request({
    url: '/role/',
    method: 'get',
    params
  })
}

export function viewRole(id) {
  return request({
    url: `/role/${id}`,
    method: 'get'
  })
}

export function addRole(data) {
  return request({
    url: '/role/',
    method: 'post',
    data
  })
}

export function editRole(id, data) {
  return request({
    url: '/role/' + id + '/',
    method: 'put',
    data
  })
}

export function saveMenu(id, data) {
  return request({
    url: '/role/' + id + '/',
    method: 'patch',
    data
  })
}

export function savePermission(id, data) {
  return request({
    url: '/role/' + id + '/',
    method: 'patch',
    data
  })
}

export function delRole(id) {
  return request({
    url: '/role/' + id,
    method: 'delete'
  })
}

// 检查角色名是否存在
export function checkRoleName(params) {
  return request({
    url: '/check/role/name/',
    method: 'get',
    params
  })
}

export function exportRoleAll() {
  return request({
    url: '/role/export_all/',
    method: 'post'
  })
}

export function exportRoleCurrent(params) {
  return request({
    url: '/role/export_current/',
    method: 'post',
    params
  })
}
